package com.einmeer.kssc_administrator.controller;

import com.einmeer.kssc_administrator.service.AdministratorsService;
import com.einmeer.kssc_administrator.vo.ResultVo;
import jakarta.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 芊嵛
 * @date 2024/1/31
 */
@RestController
@RequestMapping("/administrators")
public class AdministratorsController {
    @Resource
    private AdministratorsService administratorsService;

    /**
     * 用户登录
     *
     * @param administratorsUsername
     * @param administratorsPassword
     * @return
     */
    @GetMapping("/login/{administratorsUsername}/{administratorsPassword}")
    @CrossOrigin
    public ResultVo login(@PathVariable("administratorsUsername") String administratorsUsername, @PathVariable("administratorsPassword") String administratorsPassword) {
        System.out.println(administratorsUsername + "mim" + administratorsPassword);
        return administratorsService.login(administratorsUsername, administratorsPassword);
    }

    /**
     * 返回用户信息
     *
     * @param administratorsId
     * @return
     */
    @GetMapping("/administratorsInfo")
    @CrossOrigin
    public ResultVo administratorsInfo(@RequestParam(value = "administratorsId") Integer administratorsId) {
        return administratorsService.administratorsInfo(administratorsId);
    }

    /**
     * 修改密码
     * @param oANPassword
     * @return
     */
    @PutMapping("/changeAdministratorPassword")
    @CrossOrigin
    public ResultVo changeAdministratorPassword(@RequestBody Map oANPassword) {
        Integer administratorsId = Integer.parseInt((String) oANPassword.get("administratorsId")) ;
        String administratorsOldPassword = (String) oANPassword.get("administratorsOldPassword");
        String administratorsNewPassword = (String) oANPassword.get("administratorsNewPassword");
        return administratorsService.changeAdministratorPassword(administratorsId,administratorsOldPassword,administratorsNewPassword);
    }
}
